package com.noble.glamour.ui.agora.act.dialog;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.noble.glamour.R;
import com.noble.glamour.module.logic.application.App;
import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.library.view.base.BaseDialogFragment;
import com.noble.glamour.module.logic.config.UrlParam;
import com.noble.glamour.module.logic.request.HttpResponse;
import com.noble.glamour.module.logic.request.RequestComplete;
import com.noble.glamour.ui.agora.act.bean.RtcComplainReasons;
import com.noble.glamour.ui.agora.model.EngineConfig;
import com.noble.glamour.ui.agora.view.ViewAutoWrap;
import com.noble.library.log.PToast;

import java.util.List;

/**
 * 男用户：视频中投诉弹框
 * <p>
 * Created by Su on 2017/7/19.
 */
public class RtcVideoCommentDlg extends BaseDialogFragment implements View.OnClickListener, RequestComplete {
    private ViewAutoWrap autoWrap;

    public RtcVideoCommentDlg() {
        settWindowAnimations(R.style.AnimDownInDownOutOverShoot);
        setGravity(Gravity.BOTTOM);
        setDialogSizeRatio(0, 0);
        setCanceledOnTouchOutside(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        setContentView(R.layout.f1_chat_video_comment_dialog);
        initView();
        return getContentView();
    }

    private void initView() {
        autoWrap = (ViewAutoWrap) findViewById(R.id.view_comment_content);
        List<String> list = ModuleMgr.getCommonMgr().getCommonConfig().getVideo().getReport_reasons();

        if (list != null && !list.isEmpty())
            autoWrap.init(list, getContext(), true);
        else
            ModuleMgr.getRtcEnginMgr().reqGetComplainReasons(this);

        findViewById(R.id.btn_submit).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_submit:
                if (autoWrap.getSelectedString().size() <= 0) {
                    PToast.showShort(App.activity.getString(R.string.chat_video_complain_no));
                    return;
                }

                EngineConfig config = ModuleMgr.getRtcEnginMgr().getEngineConfig();
                ModuleMgr.getRtcEnginMgr().reqAddComplaint(config.mOtherId, autoWrap.getSelectedString(), this);
                dismiss();
                break;
        }
    }

    @Override
    public void onRequestComplete(HttpResponse response) {
        if (response.getUrlParam() == UrlParam.reqAddComplaint) {
            if (response.isOk()) {
                PToast.showShort(App.activity.getString(R.string.chat_video_complain_suc));
                return;
            }
            PToast.showShort(TextUtils.isEmpty(response.getMsg()) ?
                    App.activity.getString(R.string.chat_video_complain_error) : response.getMsg());
            return;
        }

        if (response.getUrlParam() == UrlParam.reqGetComplainReasons) {
            RtcComplainReasons reasons = (RtcComplainReasons) response.getBaseData();
            List<String> list = reasons.getReport_reasons();
            if (list != null && !list.isEmpty())
                autoWrap.init(list, getContext(), true);
        }
    }
}
